//
//  HMWelcomeVC.swift
//  swift一遍敲
//
//  Created by 刘耀宗 on 16/4/20.
//  Copyright © 2016年 刘耀宗. All rights reserved.
//

import UIKit
import SDWebImage

class HMWelcomeVC: UIViewController {
    
    override func loadView() {
        super.loadView()
        prepareUI()
        HMUserAccessModel.shareAccessModel.loadUserInfo {_ in 
            //获取信息
            let urlStr = HMUserAccessModel.shareAccessModel.userAccess!.avatar_large
            print("urlStr ==\(urlStr)")
            let url = NSURL.init(string: urlStr!)
            self.titleImageView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar_default_big"))
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
       
      
        
    }
    private func prepareUI()
    {
        self.view.addSubview(bkgImageView)
      
        self.view.addSubview(titleImageView)
        
        self.view.addSubview(welcomeLabel)
      
        
        bkgImageView.snp_makeConstraints { (make) in
            make.edges.equalTo(self.view)
        }
        //头像
        titleImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(self.view)
            make.width.equalTo(150)
            make.height.equalTo(150)
            make.top.equalTo(self.view).offset(50)
            
        }
        //文字
        welcomeLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(self.view)
            make.top.equalTo(titleImageView.snp_bottom).offset(20)
            
        }
        
      animation()
    
    
    }
    //动画
    func animation()
    {
        titleImageView.transform = CGAffineTransformMakeTranslation(
            0, 200)
            UIView.animateWithDuration(4, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 3, options: UIViewAnimationOptions(rawValue: 0), animations: {

                self.titleImageView.transform = CGAffineTransformIdentity
                
                }) { (_) in
                    print("动画完成")
                    UIApplication.sharedApplication().delegate?.window!!.rootViewController = HMMainTabbarVC()
                    
        }
        
    }
    private lazy var bkgImageView: UIImageView = {
    
        let imageView = UIImageView(image: UIImage(named: "ad_background"))
        return imageView
    }()
    //头像
    private lazy var titleImageView: UIImageView = {
        let titleView = UIImageView(image: UIImage(named: "avatar_default_big"))
        
       
        titleView.layer.cornerRadius = 75
        titleView.layer.masksToBounds = true
  
        return titleView
    
    }()
    //欢迎
    private lazy var welcomeLabel: UILabel = {
        let label = UILabel()
        label.text = "欢迎归来"
        label.font = UIFont.systemFontOfSize(14)
        label.textColor = UIColor.blackColor()
        label.sizeToFit()
        return label
    
    
    }()
    
    
    

}
